<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>AdminLTE 3 | Log in</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Font Awesome -->
    <link rel="stylesheet" href="./plugins/fontawesome-free/css/all.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="./css/adminlte.min.css">
    <!-- Google Font: Source Sans Pro -->
    <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
</head>
<body class="hold-transition login-page">
<div class="login-box">
    <div class="login-logo">
        <b>TBS</b>
    </div>
    <!-- /.login-logo -->
    <div class="card">
        <div class="card-body login-card-body">
            <form action="" method="post">
                <div class="input-group mb-3">
                    <input id="name" name="name" type="text" class="form-control" placeholder="Name">
                    <div class="input-group-append">
                        <div class="input-group-text">
                            <span class="fas fa-envelope"></span>
                        </div>
                    </div>
                </div>
                <div class="input-group mb-3">
                    <input id="password" name="password" type="password" class="form-control" placeholder="Password">
                    <div class="input-group-append">
                        <div class="input-group-text">
                            <span class="fas fa-lock"></span>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <!-- /.col -->
                    <button type="button" onclick="login()" class="btn btn-success btn-block">登录</button>
                    <!-- /.col -->
                </div>
            </form>

            <!--      <div class="social-auth-links text-center mb-3">-->
            <!--        <p>- OR -</p>-->
            <!--        <a href="#" class="btn btn-block btn-primary">-->
            <!--          <i class="fab fa-github mr-2"></i> Sign in using Github-->
            <!--        </a>-->
            <!--      </div>-->
            <!-- /.social-auth-links -->
        </div>
        <!-- /.login-card-body -->
    </div>
</div>
<!-- /.login-box -->

<!-- jQuery -->
<script src="./plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="./plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- AdminLTE App -->
<script src="./js/adminlte.min.js"></script>
<script>
    function login() {
        var opt = {
            name: $("#name").val(),
            password: $("#password").val()
        };
        console.log(JSON.stringify(opt))
        //提交ajax请求
        $.ajax({
            type: "POST",
            //请求的媒体类型
            contentType: "application/json;charset=UTF-8",
            // contentType: "application/x-www-form-urlencoded",
            //请求地址
            url: "/user/index",
            //数据，json字符串
            data: JSON.stringify(opt),
            //请求成功
            success: function (result) {
                if (result == "USER_NOT_EXIST") {
                    alert("用户不存在")
                } else if (result == "ACCOUNT_OLD") {
                    alert("账号已被冻结，请联系管理员")
                } else if (result == "PASSWORD_ERR") {
                    alert("密码输入有误")
                } else {
                    window.location.href = "index.html";
                }
            },
            //请求失败，包含具体的错误信息
            error: function (e) {
                console.log(e.status);
                console.log(e.responseText);
            }
        });
    }


</script>
</body>
</html>